<template>
  <!--  <div class="register_container"-->
  <!--       style="background-color: rgba(251,226,152,0.36);width: 100%; height:702px;margin-top: -8px ">-->
  <div class="register_box">
    <!--    style="background-color: white;width: 1100px;height: 600px;margin-top: 90px;margin-left:250px;float: left;border-radius: 20px;box-shadow: 1px 2px 3px 4px #cccccc">-->
    <!--    <div class="register_box">-->
    <div class="register_box1">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="用户名" prop="userName" class="item">
          <el-input v-model="ruleForm.userName" placeholder="请输入用户名" style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password" class="item">
          <el-input type="password" v-model="ruleForm.password" placeholder="请输入密码" autocomplete="off"
                    style="width: 300px"></el-input>
        </el-form-item>
        <el-form-item label="手机号" prop="id" class="item">
          <el-input v-model="ruleForm.id" placeholder="请输入手机号" style="width: 300px;height: 5px">
          </el-input>
        </el-form-item>
        <el-form-item label="性别" prop="sex" class="item">
          <el-radio v-model="ruleForm.sex" label="男">男</el-radio>
          <el-radio v-model="ruleForm.sex" label="女">女</el-radio>
        </el-form-item>
        <el-form-item label="年龄" prop="age" class="item">
          <el-input v-model="ruleForm.age" placeholder="请输入年龄" style="width: 300px">
          </el-input>
        </el-form-item>
        <el-form-item label="地址" prop="address" class="item">
          <el-input v-model="ruleForm.address" placeholder="请输入地址" style="width: 300px">
          </el-input>
        </el-form-item>
        <el-form-item label="邮箱" prop="email" class="item">
          <el-input v-model="ruleForm.email" placeholder="请输入邮箱" style="width: 300px">
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="registerForm('ruleForm')" align="center">录入</el-button>
          &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          <!--          <el-link v-on:click="look">查看用户信息</el-link>-->
          <el-button type="primary" @click="look">查看用户信息</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
  <!--  </div>-->
  <!--  </div>-->
</template>

<script>
  export default {
    name: "ReadUserInformation",
    data()
    {
      return {
        ruleForm: {
          userName: '',
          password: '',
          id: '',
          sex: '',
          age: '',
          address: '',
        },
        rules: {
          userName: [
            {required: true, message: '请输入用户名', trigger: 'blur'},
            {min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur'}
          ],
          password: [
            {required: true, message: '请输入密码', trigger: 'blur'},
            {min: 3, max: 6, message: '长度在 3 到 6 个字符', trigger: 'blur'}
          ],
          id: [
            {required: true, message: '请输入手机号', trigger: 'change'}
          ],
          age: [
            {required: true, message: '请输入年龄', trigger: 'blur'}
          ],
          address: [
            {required: true, message: '请填写收货地址', trigger: 'blur'}
          ]
        }
      };
    },
    methods: {
      look()
      {
        this.$router.push({path: "/userInformation"})
      },
      registerForm(formName)
      {
        this.$refs[formName].validate(async (valid) =>
        {
          if (valid)
          {
            const {data: res} = await this.$http.post('http://localhost:8888/register',
              {
                userName: this.ruleForm.userName,
                password: this.ruleForm.password,
                id: this.ruleForm.id,
                sex: this.ruleForm.sex,
                age: this.ruleForm.age,
                address: this.ruleForm.address,
                email: this.ruleForm.email,
              },
              {emulateJSON: true});//进入后端
            if (res.code === 200)
            {
              alert("保存成功！")
              // this.$router.push({path: "/UserLogin"})
            }
          } else
          {
            alert("保存失败");
            return false;
          }
        });
      },
      resetForm(formName)
      {
        this.$refs[formName].resetFields();
      }
    }
  }

</script>

<style scoped>
  .item .el-form-item__label
  {
    color: dimgrey;
    font-size: 15px;

  }

  .ti
  {
    font-size: 70px;
    color: rgba(102, 0, 0, 0.82);
    font-family: 微软雅黑
  }

  .register_box
  {
    /*background-color: rgba(251, 226, 152, 0.36);*/
    width: 80%;
    height: 80%;
    margin-top: 0px;
    margin-left: 10%;
    float: left;
    border-radius: 20px;
    box-shadow: 1px 2px 3px 4px #cccccc;
  }

  .register_box1
  {
    float: left;
    margin-left: 10%;
    margin-top: 5%;
    /*border: solid black;*/
    width: 600px;
    height: 500px;
  }

</style>
